package cn.itcast.com.homework.day729;

import java.io.*;
import java.util.Arrays;

/*
1.有这样的一个words数组，数组中每个字符串的格式为“词性:单词”
String[] words = {"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
根据单词性质动词verb全部存入verb.txt文件中
根据单词性质名词noun全部存入noun.txt文件中
 */
public class test1 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\代码\\代码\\代码\\cn\\itcast\\com\\homework\\day729","verb.txt");
        file.createNewFile();
        File file1 = new File("D:\\代码\\代码\\代码\\cn\\itcast\\com\\homework\\day729","noun.txt");
        file1.createNewFile();

        String[] words = {"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
        int length = words.length;

        FileOutputStream fileOutputStream1 = new FileOutputStream("D:\\代码\\代码\\代码\\cn\\itcast\\com\\homework\\day729\\verb.txt");
        FileOutputStream fileOutputStream2 = new FileOutputStream("D:\\代码\\代码\\代码\\cn\\itcast\\com\\homework\\day729\\noun.txt");

        for (int i = 0; i < length; i++) {
            if (words[i].startsWith("verb:")){
                fileOutputStream1.write(words[i].getBytes());
                fileOutputStream1.write(32);
            }else {
                fileOutputStream2.write(words[i].getBytes());
                fileOutputStream2.write(32);
            }
        }
        FileInputStream fileInputStream1 = new FileInputStream("D:\\代码\\代码\\代码\\cn\\itcast\\com\\homework\\day729\\verb.txt");
        FileInputStream fileInputStream2 = new FileInputStream("D:\\代码\\代码\\代码\\cn\\itcast\\com\\homework\\day729\\noun.txt");
        byte[] bytes = new byte[1024];
        fileInputStream1.read(bytes);
        System.out.println(new String(bytes));
        fileInputStream2.read(bytes);
        System.out.println(new String(bytes));

    }
}
